package com.yf1706.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yf1706.bean.CheckAccount;
import com.yf1706.dao.jpa.ICheckAccountJDAO;
import com.yf1706.dao.jpa.ICheckRuleJDAO;
import com.yf1706.dao.mybatis.ICheckAccountMDAO;
import com.yf1706.vo.CheckAccountVO;
import com.yf1706.vo.CheckUPAccountVO;

@Service
@Transactional(rollbackFor=Exception.class)
public class CheckAccountService {
   @Autowired
   private ICheckAccountJDAO caJdao;
   @Autowired
   private ICheckAccountMDAO caMdao;
   @Autowired
   private ICheckRuleJDAO crJdao;
   /**
	 * 查询所有的配卡信息
	 * @return
	 */
	public List<CheckAccount> CheckAccountList(){
		return caMdao.queryCheckAccount();
	}
	//模糊查询配卡信息
	public List<CheckAccount> getSerchCheckAccountList(int accountId ){
		return caMdao.querySerchCheckAccount(accountId);
	}
	//存储新增配卡信息
	public void addCheckAccount(CheckAccountVO caVO) {
		CheckAccount ca=new CheckAccount();
		ca.setCheckRule(crJdao.findByRuleId(caVO.getRuleId()));
		ca.setRemark(caVO.getRemark());
		ca.setMaker(caVO.getMaker());
		ca.setMakeTime(new Date());
		ca.setState("true");
		caJdao.save(ca);
	}
	//修改配卡信息
	public void updateCheckAccount(CheckUPAccountVO caVO) {
		CheckAccount ca=new CheckAccount();
		ca.setAccountId(caVO.getAccountId());
		ca.setCheckRule(crJdao.findByRuleId(caVO.getRuleId()));
		ca.setRemark(caVO.getRemark());
		ca.setMaker(caVO.getMaker());
		ca.setMakeTime(caVO.getMakeTime());
		ca.setUpdateEmp(caVO.getUpdateEmp());
		ca.setUpdateTime(new Date());
		ca.setState("true");
		caJdao.save(ca);
	}
	public void deleteCheckAccount(int id) {
		caJdao.deleteById(id);
	}
}
